package FileTree;

import java.awt.Component;
import java.text.DecimalFormat;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 *
 * @author Krisz
 */
public class FileTreeRenderer extends DefaultTreeCellRenderer{
    
    public Component getTreeCellRendererComponent(
                        JTree tree,
                        Object value,
                        boolean sel,
                        boolean expanded,
                        boolean leaf,
                        int row,
                        boolean hasFocus) {

        super.getTreeCellRendererComponent(
                        tree, value, sel,
                        expanded, leaf, row,
                        hasFocus);
        Double length = (double)((FileWrap)value).getLength();
        DecimalFormat twoDForm = new DecimalFormat("#.##");
        if (length < 1024.0){
            setToolTipText(twoDForm.format(length) + " B");
        }
        else{
            length /= 1024.0;
            if (length < 1024.0){
                setToolTipText(twoDForm.format(length) + " KB");
            }
            else{
                length /= 1024.0;
                setToolTipText(twoDForm.format(length) + " MB");
            }
        }
        return this;
    }
}
